package com.shu.mqtt;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
public class MqttTest2 {

	public static void main(String[] args) throws IOException, TimeoutException {
		testSendMqtt();
	}
	
	public static void testSendMqtt() throws IOException, TimeoutException {
	        ConnectionFactory factory = new ConnectionFactory();
	        factory.setUsername("admin");
	        factory.setPassword("admin");
	        // factory.setVirtualHost("");
	        factory.setHost("192.168.1.16");
	        factory.setPort(5672);
	        Connection conn = null;
	        Channel channel = null;
	        try {
	            conn = factory.newConnection();
	            channel = conn.createChannel();

	            byte[] messageBodyBytes = "{'text':'Hello, world!中文'}".getBytes();
	            channel.basicPublish("amq.topic", "test", null, messageBodyBytes);
//	            channel.basicConsume(arg0, arg1, arg2, arg3, arg4, arg5, arg6)
	        }finally {
	            if (channel != null) {
	                channel.close();
	            }
	            if (conn != null) {
	                conn.close();
	            }
	        }
	    }
}
